|
|
|
|
|
|
|
To specify which button is the default, you need to add another constant to the buttons argument of the MsgBox function. You can choose from four possible default button values, which are identified in the following table: |
|
|
|
|
|
|
|
|
A user might choose from seven buttons, with the selection depending on the button set used in the message box. Each of these buttons returns a different value to identify the button to your program (see Table 8.3). |
|
|
|
|
| Table 7.3 Return Values Indicate the User's Choice | | Button | Value | Constant | | OK | 1 | vbOK | | Cancel | 2 | vbCancel | | Abort | 3 | vbAbort | | Retry | 4 | vbRetry | | Ignore | 5 | vbIgnore | | Yes | 6 | vbYes | | No | 7 | vbNo |
|
|
|
|
|
|
As always, using the constant in your code rather than the actual integer value is preferable. After you know which button the user selected, you can use that information in your program. |
|
|
|
|
|
|
|
|
Making a Message Box Modal |
|
|
|
|
|
|
|
|
For completeness, you can apply one final setting to the buttons argument of the MsgBox function. You can choose to have the message box be modal for your application or for the entire system. Remember from earlier chapters that when a modal window is shown, it must be closed before continuing with the program. If you specify that the message box is modal to the system, the user must respond to the message box before he or she can do any further work on the computer at all. The system modal option should be used with extreme care. The default behavior is application modal, which means the users can continue to work in other applications. |
|
|
|
|
|
|
|
|
To use the default, application modal, you do not have to add anything to the buttons argument, or you can add the vbApplicationModal constant, which has a value of 0. To make the message box system modal, you need to add the constant vbSystemModal, which has a value of 4096, to the buttons argument. |
|
|
|
|
|